// @ 516
// _(:з」∠)_
// 格式化数据
// format data

// 判断对象空值
function isEmptyObject ( e ) {
    var t;
    for (t in e)
        return !1;
    return !0
}

// 数组去重
function toHeavy ( Arrs ) {
    var newArrs = [], json = {};

    for ( var x = 0; x < Arrs.length; x++ ) {
        if ( !json[ Arrs[x] ] ) {
            if ( Arrs[x] == null ) {
                Arrs[x] = '';
            }
            newArrs.push( Arrs[x] );
            json[ Arrs[x] ] = 1;
        }
    }

    return newArrs;
}

// 对象去重
function objToHeavy ( Arrs, key ) {
    var newArrs = [];

    for ( var i = 0; i < Arrs.length; i++ ){
    　　var flag = true;

    　　for ( var j = 0; j < newArrs.length; j++ ){
    　　　　if ( Arrs[i][ key ] == newArrs[j][ key ] ) {
    　　　　　　flag = false;
    　　　　}
    　　}

    　　if ( flag ) newArrs.push( Arrs[i] );
    }

    return newArrs;
}

// 对象排序
function objCompare ( prop ) {
    return function ( obj1, obj2 ) {
        var val1 = Number( obj1[ prop ] ),
            val2 = Number( obj2[ prop ] );

        if ( val1 < val2 ) {
            return -1;
        } else if ( val1 > val2 ) {
            return 1;
        } else {
            return 0;
        }            
    } 
}

// 时间对象排序
function objTimeCompare ( prop ) {
    return function ( obj1, obj2 ) {
        var val1 = new Date( obj1[ prop ] ).getTime(),
            val2 = new Date( obj2[ prop ] ).getTime();

        if ( val1 < val2 ) {
            return -1;
        } else if ( val1 > val2 ) {
            return 1;
        } else {
            return 0;
        }            
    } 
}

// 判断两个数组是否相等
function arrayEqual ( arr1, arr2 ) {
    if ( arr1 === arr2 ) return true;
    if ( arr1.length != arr2.length ) return false;

    for (var i = 0; i < arr1.length; ++i) {
        if (arr1[i] !== arr2[i]) return false;
    }

    return true;
}

// 判断数组包含
function isContained (a, b) {
    if( !(a instanceof Array) || !(b instanceof Array) ) return false;
    if( a.length < b.length ) return false;
    var aStr = a.toString();

    for(var i = 0, len = b.length; i < len; i++){
        if(aStr.indexOf(b[i]) == -1) return false;
    }

    return true;
}

// 深拷贝
function deepClone ( values ) {
    var copy;

    if ( null == values || "object" != typeof values ) return values;

    if ( values instanceof Date ) {
        copy = new Date();
        copy.setTime(values.getTime());
        return copy;
    }

    if ( values instanceof Array ) {
        copy = [];
        for ( var i = 0, len = values.length; i < len; i++ ) {
            copy[i] = deepClone(values[i]);
        }
        return copy;
    }

    if ( values instanceof Object ) {
        copy = {};
        for ( var attr in values ) {
            if ( values.hasOwnProperty(attr)) copy[attr] = deepClone(values[attr] );
        }
        return copy;
    }

    throw new Error("Unable to copy values! Its type isn't supported.");
}

// 生成指定范围随机数
function randomNum ( min, max ) {
    return Math.floor( min + Math.random() * ( max - min ) );
}

// 获取url指定参数
function getUrlParam ( name ) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"),
        r = window.location.search.substr(1).match( reg );

    if ( r!=null ) return decodeURIComponent(r[2]); return null;
}

// url参数转对象
function parseQueryString ( url ) {
    url = url == null ? window.location.href : url;
    var search = url.substring(url.lastIndexOf('?') + 1);

    if ( !search ) return {};
    return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}');
}